package ustc.xiaoyang.karl.hashtable;

import java.util.*;

/**
 * 49.字母异位词分组 medium
 */
public class GroupingOfAnagram49 {
    public static void main(String[] args) {

    }
    public List<List<String>> groupAnagrams(String[] strs) {
        Map<String,List<String>> m = new HashMap<>();
        for (String str : strs) {
            char[] ch = str.toCharArray();
            Arrays.sort(ch);
            String key = new String(ch);
            if(!m.containsKey(key)){
                m.put(key,new ArrayList<>());
            }
            m.get(key).add(str);
        }
        return new ArrayList<>(m.values());
    }
}
